using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace nzmq.tests
{
    [TestFixture]
    public class use_NzmqPushSocket_and_NzmqPullSocket
    {
        [Test]
        public void Push_messages()
        {
            using(var ctx = new NzmqContext())
            using (var pushSck = ctx.CreateUpstreamSocket("inproc://push"))
            using (var pullSck = ctx.CreateDownstreamSocket("inproc://push"))
            {
                pushSck.Send("hello");
                pushSck.Send(42);

                Assert.AreEqual("hello", pullSck.Receive());
                Assert.AreEqual(42, pullSck.Receive());
            }
        }

        
        [Test]
        public void Bind_puller_connect_pusher()
        {
            using (var ctx = new NzmqContext())
            using (var pullSck = ctx.CreateDownstreamSocket())
            using (var pushSck = ctx.CreateUpstreamSocket())
            {
                pullSck.Bind("inproc://pull");
                pushSck.Connect("inproc://pull");

                pushSck.Send("hello");
                pushSck.Send(42);

                Assert.AreEqual("hello", pullSck.Receive());
                Assert.AreEqual(42, pullSck.Receive());
            }
        }


        [Test]
        public void Push_to_subscriber()
        {
            using (var ctx = new NzmqContext())
            using (var pushSck = ctx.CreateUpstreamSocket("inproc://push"))
            using (var subSck = ctx.CreateSubscriberSocket("inproc://push"))
            {
                pushSck.Send("hello");
                pushSck.Send(42);

                Assert.AreEqual("hello", subSck.Receive());
                Assert.AreEqual(42, subSck.Receive());
            }
        }


        [Test]
        public void Pull_from_publisher()
        {
            using (var ctx = new NzmqContext())
            using (var pubSck = ctx.CreatePublisherSocket("inproc://pub"))
            using (var pullSck = ctx.CreateDownstreamSocket("inproc://pub"))
            {
                pubSck.Send("hello");
                pubSck.Send(42);

                Assert.AreEqual("hello", pullSck.Receive());
                Assert.AreEqual(42, pullSck.Receive());
            }
        }
        
    }
}